package com.xia.utils;

import java.util.List;

public class PageBean<T> {

    // 当前第几页
    private Integer pageNo;
    // 每页显示条数
    private Integer pageSize;
    // 数据
    private List<T> data;
    // 总共多少也
    private Integer totalNo;
    // 数据的总条数
    private Integer totalSize;

    public PageBean() {
    }

    public PageBean(Integer pageNo, Integer pageSize) {
        if (pageNo <= 0) {
            this.pageNo = 1;
        } else {
            this.pageNo = pageNo;
        }

        if (pageSize <= 0) {
            this.pageSize = 5;
        } else {
            this.pageSize = pageSize;
        }
    }

    public PageBean(Integer pageNo, Integer pageSize, List<T> data, Integer totalNo, Integer totalSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.data = data;
        this.totalNo = totalNo;
        this.totalSize = totalSize;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Integer getTotalNo() {
        return totalNo;
    }

    public void setTotalNo(Integer totalNo) {
        this.totalNo = totalNo;
    }

    public Integer getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Integer totalSize) {
        this.totalNo = (totalSize % pageSize == 0) ? (totalSize / pageSize) : (totalSize / pageSize + 1);
        this.totalSize = totalSize;
    }

    /**
     *  开始索引
     * @return pageNo
     */
    public Integer getStartIndex() {
        return (this.pageNo - 1)*this.pageSize;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", data=" + data +
                ", totalNo=" + totalNo +
                ", totalSize=" + totalSize +
                '}';
    }
}
